package com.yilin.tms.system.controller;

import com.yilin.tms.core.application.PageData;
import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.commons.annotation.NotNull;
import com.yilin.tms.core.commons.annotation.UserTarget;
import com.yilin.tms.core.entity.system.handle.OperateLog;
import com.yilin.tms.core.entity.user.UserType;
import com.yilin.tms.system.service.IOperateLogService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;

@RestController
@RequestMapping("/system/logger/")
public class LoggerController extends BaseController {

    @Resource
    IOperateLogService operateLogService;

    /**
     * 获取日志分页列表
     */
    @PostMapping("getOperateLogPage")
    @NotNull({"page", "limit"})
    @UserTarget({UserType.adminUser,UserType.platformUser})
    public ReturnData<PageData<OperateLog>> getOperateLogPage(Integer page, Integer limit) {
        PageData<OperateLog> pageData = operateLogService.getOperateLogPage(page, limit);
        return jsonView(true, "获取成功", pageData);
    }

    /**
     * 删除指定时段日志
     */
    @PostMapping("deleteOperateLogByTimeRange")
    @NotNull({"startTime","endTime"})
    @UserTarget({UserType.adminUser,UserType.platformUser})
    public ReturnData<PageData<OperateLog>> deleteOperateLogByTimeRange(Date startTime, Date endTime) {
        operateLogService.deleteOperateLogByTimeRange(startTime,endTime);
        return jsonView(true, "操作成功");
    }

    /**
     * 批量删除
     */
    @PostMapping("deleteOperateLogByIds")
    @NotNull({"operateLogIds"})
    @UserTarget({UserType.adminUser,UserType.platformUser})
    public ReturnData<PageData<OperateLog>> deleteOperateLogByIds(String[] operateLogIds) {
        operateLogService.deleteOperateLogByIds(Arrays.asList(operateLogIds));
        return jsonView(true, "操作成功");
    }

}
